package com.bll.imple.mymienAction;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bean.MymienBean;
import com.bll.Action;
import com.dao.MymienDao;
import com.dao.Page;

public class ShowMymienAction implements Action{
	public String execute(HttpServletRequest request,
			HttpServletResponse response) {

		String lujing=request.getParameter("lujing");  
		int type=Integer.parseInt(request.getParameter("typeId"));
		System.out.println("type:"+type);
		int userId=Integer.parseInt(request.getSession().getAttribute("userId").toString());
		  MymienDao dao=new MymienDao();
		  List<MymienBean> list=dao.SelectAll(type,userId);
		  
		  int totalRows=list.size();
		  int rowsPerPage=5;
		    int currentPage=1;
		    int totalPages=Page.computer(totalRows, rowsPerPage);
			if(request.getParameter("currentPage")!=null){
				currentPage=Integer.parseInt(request.getParameter("currentPage"));
				if(currentPage<1){
				
					currentPage=1;
				}else if(currentPage>totalPages){
				
					currentPage=totalPages;
				}
			}
			int currentRows=(currentPage-1)*rowsPerPage;
//			if(request.getParameter("currentRows")!=null){
//				currentRows=Integer.parseInt(request.getParameter("currentRows"));
//			}
			//System.out.println("currenet:"+currentRows);
		    
			request.setAttribute("currentPage", currentPage);
		    request.setAttribute("totalPages", totalPages);
		    MymienBean bean=dao.SelZhiding(type, userId);
		    request.setAttribute("zhidingPage",bean);
		    List<MymienBean> mymiens=dao.selectPages(currentRows, rowsPerPage, userId,type);
		    request.setAttribute("list", mymiens);
		
		//		String lujing=request.getParameter("lujing");  
//		int type=Integer.parseInt(request.getParameter("typeId"));
//		System.out.println("type:"+type);
//		int userId=Integer.parseInt(request.getSession().getAttribute("userId").toString());
//		  MymienDao dao=new MymienDao();
//		  List<MymienBean> mymiens=dao.SelectAll(type,userId);
//		 request.setAttribute("list", mymiens);
		  
		return lujing;
	}
}
